import requests

def main():
    url = "http://localhost:8080/get_pointcloud_image"

    try:
        print(f"正在访问: {url}")
        response = requests.get(url)

        # 打印基本信息
        print("\n=== 响应状态码 ===")
        print(response.status_code)

        print("\n=== 响应头 ===")
        for key, value in response.headers.items():
            print(f"{key}: {value}")

        print("\n=== 响应内容（前200字符） ===")
        print(response.text[:200])  # 只打印前200字符防止刷屏

        # 如果返回的是 JSON 数据，可以尝试解析并打印
        if 'application/json' in response.headers['Content-Type']:
            print("\n=== JSON 内容 ===")
            print(response.json())

    except requests.exceptions.ConnectionError:
        print("❌ 连接失败：无法访问服务器。请确认服务是否运行在 http://localhost:8080")
    except Exception as e:
        print(f"发生错误：{e}")


def post_server():

    url = "http://localhost:12300/gripper_server"
    data = {
        "speed": "10",
        "force": "20",
        "position": "30"
    }

    response = requests.post(url, data=data)
    print(response.status_code)
    print(response.text)
    print(response.request.headers)
    print(response.request.body)


if __name__ == "__main__":
    # main()

    post_server()



# curl http://localhost:8080/get_pointcloud_image


# curl -X POST http://localhost:8080/gripper_server \
#      -H "Content-Type: application/x-www-form-urlencoded" \
#      -d "a=10&b=20&c=30"